package jmine.tec.report.base.registry;

import java.util.Collection;
import java.util.SortedMap;
import java.util.TreeMap;

import jmine.tec.report.api.batch.ReportCreator;
import jmine.tec.report.base.AbstractReportParameter;
import jmine.tec.utils.register.Receiver;

/**
 * Registro de criadores de relatórios baseados em carteira
 * 
 * @author lundberg
 */
public class ReportRegistry implements Receiver<ReportCreator<? extends AbstractReportParameter>> {

    private SortedMap<String, ReportCreator<? extends AbstractReportParameter>> registry;

    /**
     * Construtor
     */
    public ReportRegistry() {
        this.registry = new TreeMap<String, ReportCreator<? extends AbstractReportParameter>>();
    }

    /**
     * {@inheritDoc}
     */
    public void register(Collection<? extends ReportCreator<? extends AbstractReportParameter>> registers) {
        for (ReportCreator<? extends AbstractReportParameter> creator : registers) {
            this.registry.put(creator.getCreatorKey(), creator);
        }
    }

    /**
     * Obtém o reportCreator com a chave dada.
     * 
     * @param key key
     * @return ReportCreator
     */
    public ReportCreator<? extends AbstractReportParameter> findByKey(String key) {
        return this.registry.get(key);
    }

    /**
     * Retorna uma coleção de criadores de relatórios disponíveis
     * 
     * @return collection de report creator
     */
    public Collection<ReportCreator<? extends AbstractReportParameter>> getAvailableReportCreators() {
        return this.registry.values();
    }
}
